<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <link rel="icon" href="${una}/ub-admin/img/favicon.png" type="image/x-icon">
    <link rel="shortcut icon" href="${una}/ub-admin/img/favicon.png" type="image/x-icon">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="x-ua-compatible" content="ie=edge">

    <title>发布文章 - UnaBoot</title>
    <link rel="stylesheet" href="${una}/ub-admin/plugin/fontawesome-free/css/all.min.css">
    <link rel="stylesheet" href="${una}/ub-admin/css/font-awesome.css">
    <link rel="stylesheet" href="${una}/ub-admin/css/ionicons.css">
    <link rel="stylesheet" href="${una}/ub-admin/css/adminlte.min.css">
    <link rel="stylesheet" href="${una}/ub-admin/plugin/layer/skin/default/layer.css"/>
    <link rel="stylesheet" href="${una}/ub-admin/plugin/datetimepicker/bootstrap-datetimepicker.css"/>
    <link rel="stylesheet" href="${una}/ub-admin/css/unaboot-admin.css">
    <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
    <style>
        .datetimepicker-minutes select{
            display: none!important;
        }
        .datetimepicker.datetimepicker-dropdown-bottom-right.dropdown-menu{
            top: 92px!important;
        }
    </style>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <form class="form-inline mt-3">
                <div class="form-group row">
                    <div class="col-12 mt-2">
                        <div class="custom-control custom-radio custom-control-inline pr-4">
                            <input type="radio" id="publish-now" name="type" value="1" checked class="custom-control-input">
                            <label class="custom-control-label font-weight-normal" for="publish-now">立即发布</label>
                        </div>
                        <div class="custom-control custom-radio custom-control-inline">
                            <input type="radio" id="publish-later" name="type" value="0" class="custom-control-input">
                            <label class="custom-control-label font-weight-normal" for="publish-later">定时发布</label>
                        </div>
                    </div>
                    <div class="col-12 mt-2 hidden" id="data-time">
                        <div class="form-group row" style="height: 100px;overflow-y: auto;">
                            <label for="publishDate" class="col-3 col-form-label font-weight-normal">时间:</label>
                            <div class="col-9">
                                <input type="text" name="publishDate" value="${publishDate?string("yyyy-MM-dd HH:mm:ss")}" class="form-control form-control-sm" id="publishDate" >
                            </div>
                        </div>
                    </div>
                </div>
            </form>
            <div class="pl-4 pt-2 pr-4 pb-2 bg-gray-light text-right fixed-bottom">
                <button type="button" id="close" class="btn btn-default pull-right">取消</button>
                <button type="button" id="save" class="btn btn-primary pull-right mr-2">确定</button>
            </div>
        </div>
    </div>
</div>
<script src="${una}/ub-admin/plugin/jquery/jquery.min.js"></script>
<script src="${una}/ub-admin/plugin/jquery/jquery.serialize.js"></script>
<script src="${una}/ub-admin/plugin/datetimepicker/bootstrap-datetimepicker.js"></script>
<script src="${una}/ub-admin/plugin/datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${una}/ub-admin/plugin/jquery/jquery.form.js"></script>
<script src="${una}/ub-admin/plugin/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="${una}/ub-admin/js/adminlte.js"></script>
<script type="text/javascript" src="${una}/ub-admin/plugin/layer/layer.js"></script>
<script src="${una}/ub-admin/js/jquery.validate.min.js"></script>
<script type="text/javascript">
    $(function(){
        $("#publishDate").datetimepicker({
            language:'zh-CN',
            format:'yyyy-mm-dd hh:ii:ss',
            todayBtn:false,
            autoClose:true,
            startView:0,
            minView:0,
            forceParse:0,
            minuteStep:10,
            startDate:new Date(),
            initialDate:new Date()
        });
        $("#save").on("click",function(){
            var type = $("input:radio[name='type']:checked").val();
            var publishDate = $("#publishDate").val();
            var load = layer.load(2,{shade:[0.4,'#f0f0f0']});
            $.ajax({
                type:'post',
                url:"${una}/admin/posts/${postId}/publish",
                data:{
                    type:type,
                    publishDate:publishDate
                },
                success:function(){
                    layer.alert("文章已经发布成功",{title:'系统提示信息',icon:1},function(){
                        layer.close(load);
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.location.reload();
                    });
                },
                error:function(){
                    layer.alert("服务器异常,请稍后再试",{title:'系统提示信息',icon:0},function(){
                        layer.close(load);
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    });
                }
            });
        });
        $("#close").on("click",function(){
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });

        $("input[name='type']").on("click",function(){
            var value = $("input:radio[name='type']:checked").val();
            if(value === 1){
                $("#data-time").hide();
            }else{
                $("#data-time").show();
            }
        });

    });
</script>
</body>
</html>
